package cn.edu.sgu.www.mhxysy.chain.login.impl;

import cn.edu.sgu.www.mhxysy.chain.login.UserLoginHandler;
import cn.edu.sgu.www.mhxysy.feign.clients.pms.PmsFeignService;
import cn.edu.sgu.www.mhxysy.util.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 登录处理-修改用户最后一次登录时间
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Component
public class UserUpdateHandler implements UserLoginHandler {

    private UserLoginHandler next;

    private final PmsFeignService feignService;

    @Autowired
    public UserUpdateHandler(PmsFeignService feignService) {
        this.feignService = feignService;
    }

    @Override
    public void handle() {
        feignService.updateLastLoginTime(UserUtils.getUserId(), LocalDateTime.now());

        if (next != null) {
            next.handle();
        }
    }

    @Override
    public void setParams(Object params) {

    }

    @Override
    public void setNext(UserLoginHandler next) {
        this.next = next;
    }

}